<style type="text/css">
.red {
	color: red;		
}
p {
	padding: 3px;
	margin: 0;
}

#logview p:nth-child(even) {
	background: #EAEAEA;
}

</style>
<div id="logview" style="padding: 5px 15px">
	<div class="spinner">Loading...</div>
<?php
	try {
		$m = new Mongo('10.243.118.141');
	} catch ( MongoConnectionException $e ) {
		echo '<p class="red">Couldn\'t connect to mongodb, is the "mongo" process running?</p>';
		exit();
	}
	$c = $m->selectDB('test')->selectCollection('app_log_data');
	$fields = array('time_stamp', 'message', 'log_level', 'logger', 'thread_id', 'ip_address', 'sys_pid');
	$criteria = array();
	$sort = array('time_stamp' => -1);
	//$r = $c->findOne(array(), $fields);
	//var_dump($r);
	$cursor = $c->find($criteria, $fields)->sort($sort)->limit(50);
	//var_dump($cursor);
	//var_dump($cursor->count(true));

	$i = 0;
	foreach ($cursor as $obj) {
		if ($i++ == 0) {
			echo '<input type="hidden" value="'.date('Y-m-d H:i:s',$obj['time_stamp']->sec+1).'">';
		}
		echo '<p><span>'.date('Y-m-d H:i:s',$obj['time_stamp']->sec).'</span>'
			 .printBlank(4).'<span class="">['.$obj['log_level'].']</span>'
			 .printBlank(4).'<span>'.$obj['message'].'</span></p>';
	}
	
	$m->close();
	
	function printBlank($num) {
		$str = '';
		for ($i=0; $i<$num; $i++) {
			$str = $str.'&nbsp;';
		}
		return $str;
	}
?>
</div>
